package lz.controls
{
	import com.common.utils.ObjectUtil;
	import com.common.utils.Reflection;
	
	import flash.display.Shape;
	import flash.events.MouseEvent;
	
	import lz.controls.core.UIComponent;
	import lz.controls.managers.TipsManager;

	/**
	 *能力图 
	 * @author lake
	 * 
	 */	
	public class PowerGraphics extends UIComponent
	{
		/**
		 *能力值 
		 * 依次 控球 进攻 速度 抢断 防守 力量 
		 */		
		private var _powers :Array;
		private var shape :Shape;
		private var _showTips :Boolean = false;
		
		public var mColor :uint = 0x6beaea;;
		public var mAlpha :Number = .5;
		public var isMove	:Boolean = true;
		
		public function PowerGraphics()
		{
			super();
		}
		
		public function set powers(value :Array):void
		{
			_powers = value;
			if(value == null || value.length == 0)
			{
				return;
			}
			if(_symbolSkin == null)
			{
				_symbolSkin = Reflection.createInstance("com.lz.res.PowerGraphics");
				if(_symbolSkin == null)return;
				this.addChild(_symbolSkin);
			}
			var i:int = 0;
			while(i < 6)
			{
				powers[i] = int(powers[i]);
				i++;
			}
			if(shape && shape.parent)
			{
				shape.parent.removeChild(shape);
			}
			shape =  ObjectUtil.drawPowerGraphics(powers,mColor,mAlpha);
			_symbolSkin.addChild(shape);
		}
		
		public function get powers():Array
		{
			return _powers;
		}
		
		public function set showTips(value :Boolean):void
		{
			_showTips = value;
			if(_showTips)
			{
				_symbolSkin.addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
				_symbolSkin.addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
			}
			else
			{
				_symbolSkin.removeEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
				_symbolSkin.removeEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
			}
		}
		
		public function get showTips():Boolean
		{
			return _showTips;
		}
		
		/**
		 *移上 
		 * @param e
		 * 
		 */		
		private function rollOverHandler(e :MouseEvent):void
		{
			var info :String = "";
			info += "进攻: " + powers[1] + " \n";
			info += "速度: " + powers[2] + " \n";
			info += "抢断: " + powers[3] + " \n";
			info += "控球: " + powers[0] + " \n";
			info += "防守: " + powers[4] + " \n";
			info += "力量: " + powers[5] + " \n";
			TipsManager.show("BaseTips",{tip:info},15,15,isMove);
		}
		/**
		 *移开 
		 * @param e
		 * 
		 */		
		private function rollOutHandler(e :MouseEvent):void
		{
			TipsManager.hide();
		}
	}
}